
<template>
  <div>
    <a-modal v-model="visible" centered title="标题" width="600px" @cancel="close" :destroyOnClose="true" @ok="handleOk">
      <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item ref="productCode" label="商品款号" prop="productCode">
          <a-input
          :disabled="flag"
            :maxLength="20"
            v-model.trim="form.productCode"
            @blur="
              () => {
                $refs.productCode.onFieldBlur()
              }
            "
          />
        </a-form-model-item>
        <a-form-model-item ref="tagDictCode" label="营销标识" prop="tagDictCode">
          <a-select  :disabled="flag" v-model="form.tagDictCode" placeholder="请选择" :getPopupContainer="triggerNode => triggerNode.parentNode">
            <a-select-option :value="item.value" v-for="(item, index) in advertLoc" :key="index">{{ item.text }}</a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="置顶时间">
          <a-range-picker style="width: 100%" :show-time="{ format: 'YYYY-MM-DD HH:mm:ss' }" :placeholder="['开始时间', '结束时间']" v-model="beginTime" @change="onChange" />
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </div>
</template>
<script>
import { initDictOptions, filterDictText } from '@/components/dict/JDictSelectUtil'
import { createOrUpdate } from '@/api/box/product'
import Vue from 'vue'
import { USER_INFO } from '@/store/mutation-types'
export default {
  data() {
    return {
      userInfo: Vue.ls.get(USER_INFO),
      labelCol: { span: 4 },
      wrapperCol: { span: 18 },
      visible: false,
      id: '',
      parentId: '',
      form: {
        productCode: '',
        tagDictCode: '',
        beginTime: null,
        endTime: null,
        isDel: 0
      },
      flag:false,

      beginTime: [],
      title: '',
      rules: {
        productCode: [{ required: true, message: '请填写', trigger: 'blur' }],
        tagDictCode: [{ required: true, message: '请选择', trigger: 'blur' }]
      },
      advertLoc: []
    }
  },
  mounted() {
    this.initDictConfig()
  },
  methods: {
    // 初始化字典
    initDictConfig() {
      //初始化字典 -box业务商品标签
      initDictOptions('box_product_dict').then(res => {
        if (res.success) {
          console.log(res)
          this.advertLoc = res.result
        }
      })
    },
    handleOk() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          let data = {
            requestData: {
              ...this.form,
              bizType: 'box_product_dict',

              createBy: this.userInfo.realname
            }
          }
          console.log(data)
          // return
          createOrUpdate(data).then(res => {
            if (res.code == 0) {
              this.visible = false

              this.form = {}
              this.beginTime = []
              this.$emit('restOk')
            } else {
              this.$message.warning(res.msg)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    loadData() {},
    onChange(value, dateString) {
      this.form.beginTime = dateString[0]
      this.form.endTime = dateString[1]
    },
    close() {
      this.form = {}
      this.beginTime = []
      this.flag=false
    },
    show(item) {
      if (item != 'add') {
        this.flag=true
        this.form = item
        this.beginTime = [item.beginTime, item.endTime]
        console.log(this.form)
      }
      this.visible = true
    }
  }
}
</script>
      
      <style>
</style>